<cfcomponent>
<cffunction name="getSiteMetaData" access="public" returntype="string" hint="Default script that returns the meta tags for content being displayed.">
  <cfargument name="scriptname" type="string" required="no" default="#cgi.SCRIPT_NAME#" hint="absolute path to script being called">
  <cfargument name="recid_var" type="string" required="no" default="url.id" hint="unique recordid">
  <cfargument name="contenttype" type="numeric" required="no" default="0" hint="0 for file 1 for recordid">
  <cfargument name="for_c" type="string" required="no" default="na" hint="component name">
  <cfargument name="for_a" type="string" required="no" default="na" hint="action name">
  <cfargument name="for_recid" type="numeric" required="no" default="0" hint="record id">
  <cfargument name="dsn" type="string" required="no" default="#request.dsn#" hint="loads default datasource by default">
  <cfset scriptname = listlast(scriptname, "/")>
  <cfif contenttype IS 0>
  <cfset ranthis = 1>
    <cfquery name="qmeta" datasource="#dsn#" maxrows="1">
    SELECT * FROM core_metadata
    WHERE for_file = <cfqueryparam value="#scriptname#" cfsqltype="cf_sql_varchar">
    </cfquery>
    <cfelse>
  <cfset ranthis = 2>
    <cfquery name="qmeta" datasource="#dsn#" maxrows="1">
    SELECT * FROM core_metadata
    WHERE for_c = <cfqueryparam value="#for_c#" cfsqltype="cf_sql_varchar">
    AND for_a = <cfqueryparam value="#for_a#" cfsqltype="cf_sql_varchar">
    AND for_recid = <cfqueryparam value="#for_recid#" cfsqltype="cf_sql_varchar">
    </cfquery>
  </cfif>
  <cfif qmeta.recordcount IS 0>
    <cfset ranthis = 3>
    <cfquery name="qmeta" datasource="#dsn#" maxrows="1">
        SELECT * FROM core_settings
        </cfquery>
  </cfif>
  <cfsavecontent variable="metadata">
<cfoutput query="qmeta"><title>#meta_title#</title>
<meta property="og:title" content="#meta_title#" />
<meta property="og:url" content="#request.secureurl##cgi.SCRIPT_NAME#?#cgi.QUERY_STRING#" />
<cfif len(trim(meta_image)) GT 0><meta property="og:image" content="#request.secureurl##meta_image#" /></cfif>
<meta property="og:description" content="#meta_abstract#" />
<meta property="og:site_name" content="#meta_description#" />
<meta name="description" content="#meta_description#">
<meta name="keywords" content="#meta_keywords#">
<cfif len(trim(meta_abstract)) GT 0><meta name="abstract" content="#meta_abstract#"></cfif>
<cfif len(trim(meta_robots)) GT 0><meta name="robots" content="#meta_robots#"></cfif>
<cfif len(trim(meta_googlebot)) GT 0><meta name="googlebot" content="#meta_googlebot#"></cfif>
<cfif len(trim(meta_msnbot)) GT 0><meta name="msnbot" content="#meta_msnbot#"></cfif>
<cfif len(trim(meta_lang)) GT 0><meta http-equiv="content-language" content="#meta_lang#"></cfif></cfoutput>
  </cfsavecontent>
  <cfreturn metadata>
</cffunction>
<cffunction name="genkeywords" access="public" returntype="string" hint="generates keywords for meta tags based on a block of text submitted.  Return comma delimted list of keywords.">
  <cfargument name="textblock" type="string" required="yes" default="">
  <cfset textblock = ReReplaceNoCase(#textblock#,"<[^>]*>","","ALL")>
  <cfset filterlist = "them,that,thee,thou,there,should,could,would,woulda,coulda,shoulda,shouldnt">
  <cfset keywordlist = "">
  <cfset textblock = replace(textblock, "@", "", "ALL")>
  <cfset textblock = replace(textblock, "##", "", "ALL")>
  <cfset textblock = replace(textblock, ".", "", "ALL")>
  <cfset textblock = replace(textblock, "?", "", "ALL")>
  <cfset textblock = replace(textblock, "$", "", "ALL")>
  <cfset textblock = replace(textblock, "%", "", "ALL")>
  <cfset textblock = replace(textblock, "^", "", "ALL")>
  <cfset textblock = replace(textblock, "&", "", "ALL")>
  <cfset textblock = replace(textblock, "*", "", "ALL")>
  <cfset textblock = replace(textblock, "(", "", "ALL")>
  <cfset textblock = replace(textblock, ")", "", "ALL")>
  <cfset textblock = replace(textblock, "[", "", "ALL")>
  <cfset textblock = replace(textblock, "}", "", "ALL")>
  <cfset textblock = replace(textblock, "`", "", "ALL")>
  <cfset textblock = replace(textblock, "!", "", "ALL")>
  <cfset textblock = replace(textblock, "'", "", "ALL")>
  <cfset textblock = replace(textblock, '"', "", "ALL")>
  <cfset textblock = replace(textblock, "_", "", "ALL")>
  <cfset textblock = replace(textblock, "=", "", "ALL")>
  <cfset textblock = replace(textblock, "+", "", "ALL")>
  <cfset textblock = replace(textblock, "/", "", "ALL")>
  <cfset textblock = replace(textblock, "|", "", "ALL")>
  <cfset textblock = replace(textblock, "\", "", "ALL")>
  <cfset textblock = replace(textblock, "<", "", "ALL")>
  <cfset textblock = replace(textblock, ">", "", "ALL")>
  <cfset textblock = replace(textblock, ",", "", "ALL")>
  <cfset textblock = replace(textblock, "1", "", "ALL")>
  <cfset textblock = replace(textblock, "2", "", "ALL")>
  <cfset textblock = replace(textblock, "3", "", "ALL")>
  <cfset textblock = replace(textblock, "4", "", "ALL")>
  <cfset textblock = replace(textblock, "5", "", "ALL")>
  <cfset textblock = replace(textblock, "6", "", "ALL")>
  <cfset textblock = replace(textblock, "7", "", "ALL")>
  <cfset textblock = replace(textblock, "8", "", "ALL")>
  <cfset textblock = replace(textblock, "9", "", "ALL")>
  <cfset textblock = replace(textblock, "0", "", "ALL")>
  <cfset textblock = replace(textblock, ";", "", "ALL")>
  <cfset textblock = replace(textblock, ":", "", "ALL")>
  <cfset textblock = replace(textblock, "&nbsp;", " ", "ALL")>  
  <cfset textblock = replace(textblock, " ", ",", "ALL")>
  <cfset textblock = replace(textblock, " ", "", "ALL")>
  <!---removes any extra spaces--->
  <cfloop from="#listlen(textblock)#" to="1" index="k" step="-1">
    <cfset this_kw = listgetat(textblock, k)>
    <cfif len(trim(this_kw)) LT 4 OR listcontains(filterlist, this_kw)>
      <cfset textblock = listdeleteat(textblock, k)>
    </cfif>
  </cfloop>
  <cfset keywords_array = listtoarray(textblock)>
  <cfset qkeywords = QueryNew("")>
  <cfset nColumnNumber1 = QueryAddColumn(qkeywords, "keyword", keywords_array)>
  <cfquery name="getkeywords" dbtype="query" maxrows="52">
    SELECT * FROM qkeywords 
	</cfquery>
  <cfset keywordlist = valuelist(getkeywords.keyword)>
  <cfreturn keywordlist>
</cffunction>
<cffunction name="insertmetadata" access="public" returntype="string" hint="Inserts meta data into the core_metadata table for the speciied file.">
  <cfargument name="for_file" type="string" required="no" default="">
  <cfargument name="for_c" type="string" required="no" default="">
  <cfargument name="for_a" type="string" required="no" default="">
  <cfargument name="for_recid" type="numeric" required="no" default="0">
  <cfargument name="recid_var" type="string" required="no" default="">
  <cfargument name="meta_title" type="string" required="yes" default="">
  <cfargument name="meta_desc" type="string" required="yes" default="">
  <cfargument name="meta_keywords" type="string" required="yes" default="">
  <cfargument name="meta_abstract" type="string" required="no" default="#meta_title#">
  <cfargument name="meta_image" type="string" required="no" default="">
  <cfargument name="islocked" type="numeric" required="no" default="0">
  <cfargument name="allowedit" type="numeric" required="no" default="0">
  
    <cfquery name="qmeta" datasource="#request.dsn#">
    SELECT * FROM core_metadata
    WHERE for_file = <cfqueryparam value="#for_file#" cfsqltype="cf_sql_varchar">
    AND for_c = <cfqueryparam value="#for_c#" cfsqltype="cf_sql_varchar">
    AND for_a = <cfqueryparam value="#for_a#" cfsqltype="cf_sql_varchar">
    AND for_recid = <cfqueryparam value="#for_recid#" cfsqltype="cf_sql_varchar"> 
    </cfquery>
	  <cfif qmeta.recordcount IS 0>
        <cfquery name="qinsert" datasource="#request.dsn#">
        INSERT INTO core_metadata
        (for_file, meta_description, meta_keywords, meta_abstract, meta_title, for_c, for_a, for_recid, recid_var, islocked)
        VALUES
        ('#for_file#', '#meta_desc#', '#meta_keywords#', '#meta_abstract#', '#meta_title#', '#for_c#', '#for_a#', #for_recid#, '#recid_var#', #islocked#)
        </cfquery>
        <cfelse>
        <cfif qmeta.islocked IS 0 OR allowedit IS 1>
            <cfquery name="qupdate" datasource="#request.dsn#">
            UPDATE core_metadata SET 
            meta_description = '#meta_desc#',
            meta_keywords = '#meta_keywords#',
            meta_abstract = '#meta_abstract#',
            meta_title = '#meta_title#',
            recid_var = '#recid_var#',
            for_recid = #for_recid#,
            islocked = #islocked#
            WHERE for_file = <cfqueryparam value="#for_file#" cfsqltype="cf_sql_varchar">
            AND for_c = <cfqueryparam value="#for_c#" cfsqltype="cf_sql_varchar">
            AND for_a = <cfqueryparam value="#for_a#" cfsqltype="cf_sql_varchar">
            AND for_recid = <cfqueryparam value="#for_recid#" cfsqltype="cf_sql_varchar"> 
            </cfquery>
		</cfif>
      </cfif>
</cffunction>
<cffunction name="getMetaData" access="public" returntype="query" hint="Default script that returns the meta tags for content being displayed.">
  <cfargument name="scriptname" type="string" required="no" default="#cgi.SCRIPT_NAME#" hint="absolute path to script being called">
  <cfargument name="recid_var" type="string" required="no" default="url.id" hint="unique recordid">
  <cfargument name="contenttype" type="numeric" required="no" default="0" hint="0 for file 1 for recordid">
  <cfargument name="for_c" type="string" required="no" default="na" hint="component name">
  <cfargument name="for_a" type="string" required="no" default="na" hint="action name">
  <cfargument name="for_recid" type="numeric" required="no" default="0" hint="record id">
  <cfargument name="dsn" type="string" required="no" default="#request.dsn#" hint="loads default datasource by default">
  <cfif contenttype IS 0>
    <cfquery name="qmeta" datasource="#dsn#" maxrows="1">
    SELECT * FROM core_metadata
    WHERE for_file = <cfqueryparam value="#scriptname#" cfsqltype="cf_sql_varchar">
    </cfquery>
    <cfelse>
    <cfquery name="qmeta" datasource="#dsn#" maxrows="1">
    SELECT * FROM core_metadata
    WHERE for_c = <cfqueryparam value="#for_c#" cfsqltype="cf_sql_varchar">
    AND for_a = <cfqueryparam value="#for_a#" cfsqltype="cf_sql_varchar">
    AND for_recid = <cfqueryparam value="#for_recid#" cfsqltype="cf_sql_varchar">
    </cfquery>
  </cfif>
  <cfif qmeta.recordcount IS 0>
    <cfquery name="qmeta" datasource="#dsn#" maxrows="1">
	SELECT * FROM core_settings
	</cfquery>
  </cfif>
  <cfreturn qmeta>
</cffunction>
<cffunction name="getMetaDataCount" access="public" returntype="numeric" hint="gets total number of meta data records in db">
    <cfquery name="qmeta" datasource="#request.dsn#">
    SELECT count(*) AS totalrecords FROM core_metadata
    </cfquery>
  <cfreturn qmeta.totalrecords>
</cffunction>
<cffunction name="getAllMetaData" access="public" returntype="query" hint="queries the database for all metadata (for admin use)">
    <cfargument name="startrow" type="numeric" default="0" required="no">
    <cfargument name="endrow" type="numeric" default="50" required="no">
    
    <cfquery name="qmeta" datasource="#request.dsn#">
    SELECT * FROM core_metadata
    LIMIT #startrow#, #endrow#
    </cfquery>

  <cfreturn qmeta>
</cffunction>
</cfcomponent>